package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.JinpengMap;
import com.ruoyi.service.fanruan.IJinpengMapService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地图城市表Controller
 *
 * @author ruoyi
 * @date 2020-11-11
 */
@Controller
@RequestMapping("/fanruan/city")
public class JinpengMapController extends BaseController
{
    private String prefix = "fanruan/city";

    @Autowired
    private IJinpengMapService jinpengMapService;

    @RequiresPermissions("fanruan:city:view")
    @GetMapping()
    public String city()
    {
        return "fanruan/city/city";
    }

    /**
     * 查询地图城市表列表
     */
    @RequiresPermissions("fanruan:city:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JinpengMap jinpengMap)
    {
        startPage();
        if(jinpengMap.getCity() == ""){
            jinpengMap.setCity(null);
        }
        if(jinpengMap.getProvince() == ""){
            jinpengMap.setProvince(null);
        }
        List<JinpengMap> list = jinpengMapService.selectJinpengMapList(jinpengMap);
        return getDataTable(list);
    }

    /**
     * 导出地图城市表列表
     */
    @RequiresPermissions("fanruan:city:export")
    @Log(title = "地图城市表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JinpengMap jinpengMap)
    {
        List<JinpengMap> list = jinpengMapService.selectJinpengMapList(jinpengMap);
        ExcelUtil<JinpengMap> util = new ExcelUtil<JinpengMap>(JinpengMap.class);
        return util.exportExcel(list, "city");
    }

    /**
     * 新增地图城市表
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/city/add";
    }

    /**
     * 新增保存地图城市表
     */
    @RequiresPermissions("fanruan:city:add")
    @Log(title = "地图城市表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JinpengMap jinpengMap)
    {
        return toAjax(jinpengMapService.insertJinpengMap(jinpengMap));
    }

    /**
     * 修改地图城市表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JinpengMap jinpengMap = jinpengMapService.selectJinpengMapById(id);
        mmap.put("jinpengMap", jinpengMap);
        return "fanruan/city/edit";
    }

    /**
     * 修改保存地图城市表
     */
    @RequiresPermissions("fanruan:city:edit")
    @Log(title = "地图城市表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JinpengMap jinpengMap)
    {
        return toAjax(jinpengMapService.updateJinpengMap(jinpengMap));
    }

    /**
     * 删除地图城市表
     */
    @RequiresPermissions("fanruan:city:remove")
    @Log(title = "地图城市表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jinpengMapService.deleteJinpengMapByIds(ids));
    }
}
